//Custom JS - All custom front-end jQuery

jQuery(document).ready(function() {
								
	// #################################
	// Menu
	// #################################
	var $menuli = $('#navi ul.menu').children("li");
	var $current = $(".current-menu-item,.current-menu-parent,.current-menu-ancestor");
	var $menuunit = $("#navi ul.menu li");				
	//add tri when submenu
		$menuli.children("a").each(function(i){
			$(this).siblings("ul.sub-menu").parent().children("a").children("span.subtitle").before("<div class='nav_tri nav_tri_original'></div>");
		});
	//add hover block hidden
	$menuunit.prepend("<div class='navhover'></div>");
	//hover on menu
	$menuunit.hover(function(){
		$(this).not("ul ul li").children(".navhover").slideDown(100);
		$(this).children("a").children(".nav_tri").removeClass('nav_tri_original').addClass('nav_tri_active');
		$(this).children("a").addClass('menu_active');
		$("#navi li li").removeClass("navhover");
		$(this).find('ul:first').delay(150).slideDown(200);
	},function(){	
		$(this).not($current).children("a").children(".nav_tri").removeClass('nav_tri_active').addClass('nav_tri_original');
		$(this).children(".navhover").delay(100).slideUp(100);
		$(this).not($current).children("a").removeClass('menu_active');
		$(this).find('ul:first').slideUp(100);
	})
	$current.children("a").addClass('menu_active');
	$current.children("a").children(".nav_tri").removeClass('nav_tri_original').addClass('nav_tri_active');
	// #################################
	// Search form
	// #################################
	$(" input.textboxsearch ").focus(function(){
		//$(this).siblings('.boxborder').fadeIn(500);
		$(this).parent().addClass("search-formhover");
		}).focusout(function(){
		//$(this).siblings('.boxborder').fadeOut(200);
		 $(this).parent().removeClass("search-formhover");
	 });
	$(".textboxsearch_header").focus(function(){
		$(this).parent().removeClass("search-form_header").addClass("search_header_over");	
		$(this).parent().animate({width:"175px"},300);
	}).focusout(function(){
		$(this).parent().removeClass("search_header_over").addClass("search-form_header");
		$(this).parent().animate({width:"120px"},300);
	});

	// #################################
	// ZOOM PORTFOLIO HOVER
	// #################################

		$("li.list_box a").hover(function(){							   
			$(this).children(".back").fadeIn(200);
		},function() {
			$(this).children(".back").fadeOut(100);
		});
		$("ul#list_wrap,ul#list_wrap_col2").find("li.listbox_ufullimg").hover(function(){							   
			$(this).find(".back").fadeIn(200);
			$(this).find(".icozoom").animate({ left:"33%"}, 300 );
			$(this).find(".icomore").animate({ right:"33%"}, 300 );
		},function() {
			$(this).find(".back").fadeOut(100);
			$(this).find(".icozoom").animate({ left:"0"}, 200 );
			$(this).find(".icomore").animate({ right:"0"}, 200 );
		});
		$("ul#list_wrap_col2_c1").find("li.listbox_ufullimg").hover(function(){							   
			$(this).find(".back").fadeIn(200);
			$(this).find(".icozoom").animate({ left:"40%"}, 300 );
			$(this).find(".icomore").animate({ right:"40%"}, 300 );
		},function() {
			$(this).find(".back").fadeOut(100);
			$(this).find(".icozoom").animate({ left:"0"}, 200 );
			$(this).find(".icomore").animate({ right:"0"}, 200 );
		});
	// #################################
	// shortcode image
	// #################################
		$('body').ready(function(){
			$('.imageshover .imageshoverp').fadeOut(0);
			});
		$(".imageshover").hover(function(){
			$(this).find('.imageshoverp').fadeIn(100);
		},function(){
		$(this).find('.imageshoverp').fadeOut(100);
		});	
	// #################################
	// Show - Hide
	// ################################	
		// Respond form
		$(".respondbtn").click(function () {
			$("#respondwrap").slideToggle(500, function() {
				if ($(this).is(":visible")) {
					$('html, body').animate({scrollTop: $(this).offset().top}, 500)
				}
			});
		});
		// Shortcode  Fold - Unfold
		$(".job_title").click(function () {
			$(this).siblings('.job_desc').slideToggle(500, function() {
				if ($(this).is(":visible")) {
					$('html, body').animate({scrollTop: $(this).offset().top}, 500)
				}
			});
		});
		// Footer Contact info.
		$("#footer_trggle").click(function () {
			$("#footunder").slideToggle(500, function() {
				if ($(this).is(":visible")) {
					$('html, body').animate({scrollTop: $(this).offset().top}, 300)
					$("#footer_trggle").removeClass('footer_open').addClass('footer_close');
				}else{
					$("#footer_trggle").removeClass('footer_close').addClass('footer_open');
				}
			});
		});
	// #################################
	// Back Top
	// ################################	
	/**/
		$("#top").hide();
		$(function () {
			$(window).scroll(function(){
				if ($(window).scrollTop()>100){
					$("#top").fadeIn(300);
				}else{
					$("#top").fadeOut(300);
				}
			});
			$("#top").click(function(){
				$('body,html').animate({scrollTop:0},500);
				return false;
			});
		});
	// #################################
	// Verification Form
	// ################################
	//verification Footer-contact-form
jQuery(document).ready(function($){ 
		$('form#contact-form').submit(function() {
			//$('form#contact-form .error').remove();
			//$('form#contact-form .required').remove();
			var hasError = false;
			$('.requiredField').each(function() {
				if(jQuery.trim($(this).val()) == '' || jQuery.trim($(this).val()) == 'Name*' || jQuery.trim($(this).val()) == 'Email*' || jQuery.trim($(this).val()) == 'Required' || jQuery.trim($(this).val()) == 'Invalid email') {
					$(this).attr("value","Required");
					hasError = true;
				}else if($(this).hasClass('email')) {
            	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
            	if(!emailReg.test(jQuery.trim($(this).val()))) {
            		$(this).attr("value","Invalid email");
            		hasError = true;
            		}
           		}else{
				}
			});
			//After verification , print some infos. 
			if(!hasError) {
				$('form#contact-form #idi_send').fadeOut('normal', function() {										  
					$(this).parent().append('<p class="sending">Sending...</p>');
				});
				var formInput = $(this).serialize();
				$.post($(this).attr('action'),formInput, function(data){
					$('form#contact-form').slideUp("fast", function() {
						$(this).before('<p class="success">Thanks, Your email was successfully sent.</p>');
						$('.sending').fadeOut();
					});
				});
			}
			return false;
	
		});
});
     //verification Comment
jQuery(document).ready(function($){ 
          $('form#commentform').submit(function() {
               var hasError = false;
               $('.requiredFieldcomm').each(function() {
                    if(jQuery.trim($(this).val()) == '' || jQuery.trim($(this).val()) == 'Name*' || jQuery.trim($(this).val()) == 'Email*' || jQuery.trim($(this).val()) == 'Required' || jQuery.trim($(this).val()) == 'Invalid email') {
                         $(this).attr("value","Required");
                         hasError = true;
                    } else if($(this).hasClass('email')) {
						 var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
						 if(!emailReg.test(jQuery.trim($(this).val()))) {
							  $(this).attr("value","Invalid email");
							  hasError = true;
						 }
					}else{
					}
               });
               //After verification , print some infos. 
			if(!hasError) {
				$('form#commentform .send_btn').fadeOut('normal', function() {										  
					$(this).parent().append('<span class="sending">Sending...</span>');
				});
				var formInput = $(this).serialize();
				$.post($(this).attr('action'),formInput, function(data){
					$('form#commentform').slideUp("fast", function() {
						$(this).before('<p class="success">Thanks, Your comment was successfully sent.</p>');
						$('.sending').fadeOut();
					});
				});
			}
               return false;
     
          });
});

	// ######################################
	// //Responsive Layout - isotope trigger
	// #####################################
		/**/
	$(window).load(function(){
		var $container = $('#list_wrap');
		$container.imagesLoaded(function(){
		  $container.isotope({
			//transformsEnabled: false,
			itemSelector : '.list_box'
		  });
		});
		//Filterable 
		$('#filterable a').click(function(){
			$(this).css('outline','none');
			$('ul#filterable .current').removeClass('current');
			$(this).parent().addClass('current');	
			var selector = $(this).attr('data-filter');
			$container.isotope({ filter: selector });
			return false;
		});
		//Resize screen 
		$(window).bind('smartresize.isotope',function(){
		  $container.isotope({
		  	itemSelector : '.list_box'
		  });
		});
		//Infinits Scroll 
		
	});

	// #################################
	// Responsive Menus
	// ################################
(function($){

  //variable for storing the menu count when no ID is present
  var menuCount = 0;
  
  //plugin code
  $.fn.mobileMenu = function(options){
    
    //plugin's default options
    var settings = {
      switchWidth: 930,
      topOptionText: 'Menu',
      indentString: '---'
    };
    
    
    //function to check if selector matches a list
    function isList($this){
      return $this.is('ul, ol');
    }
  
  
    //function to decide if mobile or not
    function isMobile(){
      return ($(window).width() < settings.switchWidth);
    }
    
    
    //check if dropdown exists for the current element
    function menuExists($this){
      
      //if the list has an ID, use it to give the menu an ID
      if($this.attr('id')){
        return ($('#mobileMenu_'+$this.attr('id')).length > 0);
      } 
      
      //otherwise, give the list and select elements a generated ID
      else {
        menuCount++;
        $this.attr('id', 'mm'+menuCount);
        return ($('#mobileMenu_mm'+menuCount).length > 0);
      }
    }
    
    
    //change page on mobile menu selection
    function goToPage($this){
      if($this.val() !== null){document.location.href = $this.val()}
    }
    
    
    //show the mobile menu
    function showMenu($this){
      $this.css('display', 'none');
      $('#mobileMenu_'+$this.attr('id')).show();
    }
    
    
    //hide the mobile menu
    function hideMenu($this){
      $this.css('display', '');
      $('#mobileMenu_'+$this.attr('id')).hide();
    }
    
    
    //create the mobile menu
    function createMenu($this){
      if(isList($this)){
                
        //generate select element as a string to append via jQuery
        var selectString = '<select id="mobileMenu_'+$this.attr('id')+'" class="mobileMenu">';
        
        //create first option (no value)
        selectString += '<option value="">'+settings.topOptionText+'</option>';
        
        //loop through list items
        $this.find('li').each(function(){
          
          //when sub-item, indent
          var levelStr = '';
          var len = $(this).parents('ul, ol').length;
          for(i=1;i<len;i++){levelStr += settings.indentString;}
          
          //get url and text for option
          var link = $(this).find('a').attr('href');
          var text = levelStr + $(this).clone().find('ul, ol, span').remove().end().text();
          
          //add option
          selectString += '<option value="'+link+'">'+text+'</option>';
        });
        
        selectString += '</select>';
        
        //append select element to ul/ol's container
        $this.parent().append(selectString);
        
        //add change event handler for mobile menu
        $('#mobileMenu_'+$this.attr('id')).change(function(){
          goToPage($(this));
        });
        
        //hide current menu, show mobile menu
        showMenu($this);
      } else {
        alert('mobileMenu will only work with UL or OL elements!');
      }
    }
    
    
    //plugin functionality
    function run($this){
      
      //menu doesn't exist
      if(isMobile() && !menuExists($this)){
        createMenu($this);
      }
      
      //menu already exists
      else if(isMobile() && menuExists($this)){
        showMenu($this);
      }
      
      //not mobile browser
      else if(!isMobile() && menuExists($this)){
        hideMenu($this);
      }

    }
    
    //run plugin on each matched ul/ol
    //maintain chainability by returning "this"
    return this.each(function() {
      
      //override the default settings if user provides some
      if(options){$.extend(settings, options);}
      
      //cache "this"
      var $this = $(this);
    
      //bind event to browser resize
      $(window).resize(function(){run($this);});

      //run plugin
      run($this);

    });
    
  };
  
})(jQuery);

	// #################################
	// Triggle - Responsive Menus
	// ################################
	$('#menu-navi').mobileMenu();
	
	// #################################
	// Triggle - flexslider
	// ################################
	$('.flexslider').flexslider();
	
	// #################################
	// Reponsive sidebar open
	// ################################
	$(".clum2_sidebar_unit h3 span").click(function () {
		$(this).parent().siblings('.widget_con').slideToggle(500, function() {
			/**/if ($(this).is(":visible")) {
				$(this).siblings('h3').children('span').removeClass('widget_open').addClass('widget_close');
			}else{
				$(this).siblings('h3').children('span').removeClass('widget_close').addClass('widget_open');
			}
		});
	});
	
	// #################################
	// Client for image in list
	// #################################
		if(navigator.platform == "iPhone" || navigator.platform == "iPad" || navigator.platform == 'iPod') {
			  $('img').css('margin-bottom','-6px');
		}
		/*if(navigator.platform == "Linux armv71") {
			  $('img').css('margin-bottom','-7px');
		}*/
});